package com.demo.security;

import java.io.IOException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * Base64编码和解码
 *
 * @author lee9213@163.com
 * @version 1.0
 * @date 2017/3/17 11:30
 */
public class Base64Util {

    /**
     * base64编码
     *
     * @param bytes
     * @return
     */
    public static String byte2base64(byte[] bytes) {
        BASE64Encoder base64Encoder = new BASE64Encoder();
        return base64Encoder.encode(bytes);
    }

    /**
     * base64解码
     *
     * @param content
     * @return
     * @throws IOException
     */
    public static byte[] base642byte(String content) throws IOException {
        BASE64Decoder base64Decoder = new BASE64Decoder();
        return base64Decoder.decodeBuffer(content);
    }
}
